Skip to content

[OptimizeInstructions] Fix loop effects in areConsecutiveInputsEqual - #9426

Open
tlively wants to merge 1 commit into
mainfrom
optimize-instructions-loop-fallthrough-effects
Open

tlively wants to merge 1 commit into
mainfrom
optimize-instructions-loop-fallthrough-effects

Conversation

@tlively

@tlively tlively commented Nov 24, 2026

Copy link
Copy Markdown
Member

When walking the right-hand input's fallthrough chain in OptimizeInstructions::areConsecutiveInputsEqual, breaking out of the ChildIterator loop upon seeing the immediate fallthrough child skipped any subsequent children (such as the unreachable ifFalse arm of an If, a Break condition, or a RefCast/BrOn descriptor). While those children execute after (or instead of) the fallthrough expression when there is no enclosing loop, once the right-hand traversal enters a named Loop, control flow can cycle back so those skipped children execute on an earlier iteration before a subsequent evaluation of the fallthrough expression. For example, a select whose second arm was a loop containing an if with an unreachable else modifying a local and branching back to the loop falsely compared equal to the first arm and dropped the first arm.

Track whether the right-hand fallthrough traversal has entered a named Loop, and once inside one, continue walking all remaining non-fallthrough children into interferingEffects rather than breaking at the immediate fallthrough child.

When walking the right-hand input's fallthrough chain in `OptimizeInstructions::areConsecutiveInputsEqual`, breaking out of the `ChildIterator` loop upon seeing the immediate fallthrough child skipped any subsequent children (such as the unreachable `ifFalse` arm of an `If`, a `Break` condition, or a `RefCast`/`BrOn` descriptor). While those children execute after (or instead of) the fallthrough expression when there is no enclosing loop, once the right-hand traversal enters a named `Loop`, control flow can cycle back so those skipped children execute on an earlier iteration before a subsequent evaluation of the fallthrough expression. For example, a `select` whose second arm was a `loop` containing an `if` with an unreachable `else` modifying a local and branching back to the loop falsely compared equal to the first arm and dropped the first arm.

Track whether the right-hand fallthrough traversal has entered a named `Loop`, and once inside one, continue walking all remaining non-fallthrough children into `interferingEffects` rather than breaking at the immediate fallthrough child.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant